﻿using System;

namespace Ipmce.RemoteVoting.Common.Tools.CardReader.ImageParsing
{
	class ByteArrayWithTag : LdsTagElement
	{
		private byte[] _value;
		private readonly int _size;

		protected override int GetChildrenSize()
		{
			return _size;
		}

		protected override int ParseChildren(byte[] data, int offset)
		{
			_value = new byte[_size];
			Array.Copy(data, offset, _value, 0, _value.Length);
			return offset + _value.Length;
		}

		protected override int WriteChildren(byte[] data, int offset)
		{
			Array.Copy(_value, 0, data, offset, _value.Length);
			return offset + _value.Length;
		}

		public byte[] Value { get { return _value; } }

		public ByteArrayWithTag(byte[] tag, int size, bool optional = false) :
			base(tag, false, size, optional)
		{
			_size = size;
		}

		public ByteArrayWithTag(byte[] tag, byte[] value, bool optional = false)
			: base(tag, false, value.Length, optional)
		{
			_value = value;
			_size = value.Length;
		}
	}
}